package com.yoona.system.controller;


import com.yoona.log.persistence.MyLog;
import com.yoona.system.service.IDynamicService;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * <p>
 * 动态表 前端控制器
 * </p>
 *
 * @author yoonada
 * @since 2020-11-03
 */
import com.yoona.common.auth.CheckLogin;
import com.yoona.common.response.BaseResponse;
import com.yoona.system.entity.Dynamic;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Email: m15602498163@163.com
 * @Author: yoonada
 * @Date: 2020/9/21
 * @Time: 8:43 下午
 * @Msg:
 */
@Api(tags = "动态")
@CrossOrigin
@RestController
@RequestMapping("/dynamic")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DynamicController {

    private final IDynamicService dynamicService;

    @MyLog("发动态")
    @CheckLogin
    @ApiOperation("发动态")
    @PostMapping("/publishDynamic")
    public BaseResponse<Object> publishDynamic(String dynamicContent, String pictureUrl, String avatarUrl, String nickName) {
        return dynamicService.publishDynamic(dynamicContent,pictureUrl,avatarUrl,nickName);
    }

    @ApiOperation("获取动态")
    @GetMapping(value = "/selectAllDynamicList")
    public BaseResponse<List<Dynamic>> selectAllDynamicList(){
        return dynamicService.selectAllDynamicList();
    }

    @ApiOperation("获取动态条数并根据页面和条数分页")
    @GetMapping(value = "/selectAllDynamicListByPage")
    public BaseResponse<List<Dynamic>> selectAllDynamicListByPage(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage,
                                                                  @RequestParam(value = "size",defaultValue = "4") Integer size){
        return dynamicService.selectAllDynamicListByPage(currentPage,size);
    }


    @ApiOperation("根据动态id获取动态详情")
    @GetMapping(value = "/findDynamicById")
    public BaseResponse<List<Dynamic>> findDynamicById(String dynamicId){
        return dynamicService.findDynamicById(dynamicId);
    }

    @MyLog("获取个人动态")
    @CheckLogin
    @ApiOperation("获取个人动态")
    @GetMapping(value = "/personalDynamic")
    public BaseResponse<List<Dynamic>> personalDynamic(){
        return dynamicService.personalDynamic();
    }

    @MyLog("删除动态")
    @CheckLogin
    @ApiOperation("删除动态")
    @PostMapping(value = "/deleteDynamic")
    public BaseResponse<Object> deleteDynamic(String dynamicId){
        return dynamicService.deleteDynamic(dynamicId);
    }


}
